﻿using System.Net;
using System.Web.Mvc;
using Matrix.Common.Utility;
using Matrix.MaKaYunShang.BLL;

namespace Matrix.MaKaYunShang.McMagWeb.Controllers
{
    [Authorization]
    public class HomeController : BaseController
    {
        // 框架页用于SignalR 单点采集
        public ActionResult Frame()
        {
            ViewBag.CurrentShopId = CurrentUser.ShopId;
            ViewBag.CurrentAccountId = CurrentUser.AccountId;

            return View();
        }

        // 首页
        public ActionResult Index()
        {
            var localProjectInfo = GetCurrentMatrixCloudProjectInfo(MkysMcMagMcId);
            if (localProjectInfo == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var model = McAccountsBLL.Instance.GetModelWithRoleInfo(CurrentUser.AccountId, localProjectInfo);
            if (model == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            ViewBag.FixedQrCode = System.Configuration.ConfigurationManager.AppSettings["Supercloudcard"] + "&Id=" + EncryptionLib.Encrypt(model.ShopId.ToString());
            var shopSubsidiaryInfo = ShopSubsidiaryInfoBLL.Instance.GetModelByShopId(CurrentUser.ShopId);
            if(shopSubsidiaryInfo != null)
            {
                model.AccountMoney = shopSubsidiaryInfo.AccountMoney;
                model.CanSendCard = shopSubsidiaryInfo.TotalCanSendCard - shopSubsidiaryInfo.AlreadySendCard;
            }
            return View(model);
        }

        public ActionResult Instructions()
        {
            return View();
        }
    }
}